package atlantik.game.action;

import modelz.UpdateableAction;
import modelz.UpdateableCollection;
import modelz.latebinding.LateBindingProvider;
import atlantik.game.Atlantik;
import atlantik.game.AtlantikState;
import atlantik.game.Player;

public abstract class AtlantikAction<T extends AtlantikAction<T>> extends
		UpdateableAction<T, Player> {

	protected final Atlantik client;

	protected AtlantikAction(Atlantik client) {
		super(new PlayerBindingProvider(client));
		this.client = client;
	}

	public boolean canPerform() {
		return getItem() != null;
	}

	protected Player self() {
		return getItem();
	}

	private static class PlayerBindingProvider implements LateBindingProvider<Player> {

		private final AtlantikState state;

		public PlayerBindingProvider(Atlantik client) {
			this.state = client.getState();
		}

		public Player gatherItem() {
			return state.self();
		}

		public UpdateableCollection<Player> getLateBindingCollection() {
			return state.players();
		}
		
	}

}
